<template>
	<view>
		<view class="change_pwd_box">
			<text>支付密码</text>
			<u--input type="password" placeholder="请输入支付密码" border="bottom" maxlength="6" v-model="new_pwd"></u--input>
			<text>确认密码</text>
			<u--input type="password" placeholder="请输入支付密码" border="bottom" maxlength="6" v-model="new_pwds"></u--input>
		</view>
		<view class="order" @click="_order">确认</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				new_pwd: '',
				new_pwds: '',
				userinfo: {}
			}
		},
		onLoad() {
			this.userinfo = uni.getStorageSync('userinfo');
			this.getUserInfo5()
		},
		methods: {
			async _order() {
				if (this.new_pwd == '' || this.new_pwd == null) {
					uni.showToast({
						title: '请输入支付密码',
						icon: 'none'
					})
					return false
				} else {
					var x = /^[0-9]{6,6}$/
					if (!x.test(this.new_pwd)) {
						uni.showToast({
							title: '请输入正确的支付密码',
							icon: 'none'
						})
						return false
					}
				}
				if (this.new_pwds == '' || this.new_pwds == null) {
					uni.showToast({
						title: '请输入确认密码',
						icon: 'none'
					})
					return false
				}
				if (this.new_pwd != this.new_pwds) {
					uni.showToast({
						title: '两次密码不正确',
						icon: 'none'
					})
					return false
				}
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp5({
					url: 'Secret/pay_pass',
					data: {
						password: this.new_pwd
					},
					header: {
						'token': this.userinfo.token
					}
				});
				uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				if (res.code == 1) {
					setTimeout(function() {
						uni.navigateBack({
							delta: 1 // 返回的页面数，如果为1表示返回上一页
						});
					},1500)
				}
			},
			// 用户信息
			async getUserInfo5() {
				const {
					data: res
				} = await this.$myHttp5({
					url: 'user/getUserInfo',
					header: {
						'token': this.userinfo.token
					}
				});
				if (res.code == 1) {
					res.data.token = this.userinfo.token
					this.userinfo = res.data
					uni.setStorageSync('userinfo', res.data);
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.change_pwd_box {
		padding: 30rpx;
		box-sizing: border-box;

		text {
			font-size: 28rpx;
			color: #333;
			padding-left: 10rpx;
			margin: 20rpx 0;
			display: block;
		}

		input {
			padding: 10rpx;
			border-bottom: #eeeeee 1px solid;
			font-size: 28rpx;
		}
	}

	.order {
		background-color: #1296db;
		margin: 50rpx 20rpx;
		text-align: center;
		padding: 30rpx 0;
		border-radius: 10rpx;
		color: #fff;
		transition: all 0.5s;
	}

	.order:active {
		background-color: #1296db;
	}
</style>
<style>
	.placeholder-class {
		color: #e1e1e1;
	}
</style>
<style scoped lang="scss">
	.placeholder-class {
		color: #e1e1e1;
	}
</style>